package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.Map; 
 import com.opensymphony.xwork2.ActionContext; 
import java.util.Collection; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.test.context.ContextConfiguration;
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQuyenChiTietService;import com.lb.jwitter.service.TblTaiKhoan;import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyen;
import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyenService;
import com.lb.jwitter.service.TblQLDTTXAThongBaoTuyenSinh;
import com.lb.jwitter.service.TblQLDTTXAThongBaoTuyenSinhService;

import com.lb.jwitter.service.TblQLDTTXADMChiNhanh;
import com.lb.jwitter.service.TblQLDTTXADMChiNhanhService;

import com.lb.jwitter.service.TblQLDTTXADMKhoa;
import com.lb.jwitter.service.TblQLDTTXADMKhoaService;

import com.lb.jwitter.service.TblQLDTTXADMNganh;
import com.lb.jwitter.service.TblQLDTTXADMNganhService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHoSoXetTuyenUpdateAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id;
 }

    public void setId(int id) {
       this.id = id;
 }

    private String email; 
    public void setEmail(String email) {
       this.email = email;
 }

    public String getEmail() {
       return email;
 }

    private String diaChi; 
    public void setDiaChi(String diaChi) {
       this.diaChi = diaChi;
 }

    public String getDiaChi() {
       return diaChi;
 }

    private String diaChiLienLac; 
    public void setDiaChiLienLac(String diaChi) {
       this.diaChiLienLac = diaChi;
 }

    public String getDiaChiLienLac() {
       return diaChiLienLac;
 } 
    private String dienThoai; 
    public void setDienThoai(String dienThoai) {
       this.dienThoai = dienThoai;
 }

    public String getDienThoai() {
       return dienThoai;
 }

    private String diDong;
    private String hoTen; 
    public void setHoTen(String hoTen) {
       this.hoTen = hoTen;
 }

    public String getHoTen() {
       return hoTen;
 }
    private String ten; 
    public void setTen(String ten) {
       this.ten = ten;
 }

    public String getTen() {
       return ten;
 }

    private String hinhAnh; 
    public void setHinhAnh(String hinhAnh) {
       this.hinhAnh = hinhAnh;
 }

    public String getHinhAnh() {
       return hinhAnh;
 }

    private String maHoSo; 
    public void setMaHoSo(String maHoSo) {
       this.maHoSo = maHoSo;
 }

    public String getMaHoSo() {
       return maHoSo;
 }

    private String ngaySinh; 
    public void setNgaySinh(String ngaySinh) {
       this.ngaySinh = ngaySinh;
 }

    public String getNgaySinh() {
       return ngaySinh;
 }

    private String noiSinh; 
    public void setNoiSinh(String noiSinh) {
       this.noiSinh = noiSinh;
 }

    public String getNoiSinh() {
       return noiSinh;
 }

    private int gioiTinh; 
    public void setGioiTinh(int gioiTinh) {
       this.gioiTinh = gioiTinh;
 }

    public int getGioiTinh() {
       return gioiTinh;
 }

    private int thongBaoId; 
    public void setThongBaoId(int thongBaoId) {
       this.thongBaoId = thongBaoId;
 }

    public int getThongBaoId() {
       return thongBaoId;
 }

    private TblQLDTTXAThongBaoTuyenSinhService tblQLDTTXAThongBaoTuyenSinhService; 

    private int chiNhanhId; 
    public void setChiNhanhId(int chiNhanhId) {
       this.chiNhanhId = chiNhanhId;
 }

    public int getChiNhanhId() {
       return chiNhanhId;
 }

    private TblQLDTTXADMChiNhanhService tblQLDTTXADMChiNhanhService; 

    private int trangThaiId; 
    public void setTrangThaiId(int trangThaiId) {
       this.trangThaiId = trangThaiId;
 }

    public int getTrangThaiId() {
       return trangThaiId;
 }

    private int khoaId; 
    public void setKhoaId(int khoaId) {
       this.khoaId = khoaId;
 }

    public int getKhoaId() {
       return khoaId;
 }

    private TblQLDTTXADMKhoaService tblQLDTTXADMKhoaService; 

    private int nganhId; 
    public void setNganhId(int nganhId) {
       this.nganhId = nganhId;
 }

    public int getNganhId() {
       return nganhId;
 }

    private TblQLDTTXADMNganhService tblQLDTTXADMNganhService; 

    private TblQLDTTXAHoSoXetTuyen tblQLDTTXAHoSoXetTuyen; 
    public void setTblQLDTTXAHoSoXetTuyen (TblQLDTTXAHoSoXetTuyen tblQLDTTXAHoSoXetTuyen) {
        this.tblQLDTTXAHoSoXetTuyen = tblQLDTTXAHoSoXetTuyen;
 }

    private TblQLDTTXAHoSoXetTuyenService tblQLDTTXAHoSoXetTuyenService; 

	private int preUpdate(Message msg, TblQLDTTXAHoSoXetTuyen obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblQLDTTXAHoSoXetTuyen obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HoSoXetTuyen", "sua")){ 
        return "noprivilege"; 
    } 
        tblQLDTTXAHoSoXetTuyenService = (TblQLDTTXAHoSoXetTuyenService) context.getBean("tbl_QLDTTXA_HoSoXetTuyenClient"); 
        tblQLDTTXAThongBaoTuyenSinhService = (TblQLDTTXAThongBaoTuyenSinhService) context.getBean("tbl_QLDTTXA_ThongBaoTuyenSinhClient"); 

        tblQLDTTXADMChiNhanhService = (TblQLDTTXADMChiNhanhService) context.getBean("tbl_QLDTTXA_DM_ChiNhanhClient"); 

        tblQLDTTXADMKhoaService = (TblQLDTTXADMKhoaService) context.getBean("tbl_QLDTTXA_DM_KhoaClient"); 

        tblQLDTTXADMNganhService = (TblQLDTTXADMNganhService) context.getBean("tbl_QLDTTXA_DM_NganhClient"); 

        msg = new Message(); 
        tblQLDTTXAHoSoXetTuyen = tblQLDTTXAHoSoXetTuyenService.gettblQLDTTXAHoSoXetTuyen(new Long(id)); 
        tblQLDTTXAHoSoXetTuyen.setEmail(email); 
        tblQLDTTXAHoSoXetTuyen.setDiaChi(diaChi); 
        tblQLDTTXAHoSoXetTuyen.setDiaChiLienLac(diaChiLienLac); 
        tblQLDTTXAHoSoXetTuyen.setDienThoai(dienThoai); 
        tblQLDTTXAHoSoXetTuyen.setDiDong(diDong);
        tblQLDTTXAHoSoXetTuyen.setHoTen(hoTen.toUpperCase()); 
        tblQLDTTXAHoSoXetTuyen.setTen(ten.toUpperCase()); 
        tblQLDTTXAHoSoXetTuyen.setHinhAnh(hinhAnh); 
        tblQLDTTXAHoSoXetTuyen.setMaHoSo(maHoSo); 
       DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
       Date dd = df.parse(ngaySinh); 
       GregorianCalendar c = new GregorianCalendar(); 
       c.setTime(dd);
       XMLGregorianCalendar d = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); 
        tblQLDTTXAHoSoXetTuyen.setNgaySinh(d); 
        tblQLDTTXAHoSoXetTuyen.setNoiSinh(noiSinh); 
        if(gioiTinh == 1){ 
           tblQLDTTXAHoSoXetTuyen.setGioiTinh(true); 
       } else { 
           tblQLDTTXAHoSoXetTuyen.setGioiTinh(false); 
       } 
        tblQLDTTXAHoSoXetTuyen.setThongBaoId(tblQLDTTXAThongBaoTuyenSinhService.gettblQLDTTXAThongBaoTuyenSinh(new Long(thongBaoId))); 
        
        tblQLDTTXAHoSoXetTuyen.setChiNhanhId(tblQLDTTXADMChiNhanhService.gettblQLDTTXADMChiNhanh(new Long(chiNhanhId))); 

//      tblQLDTTXAHoSoXetTuyen.setTrangThaiId(trangThaiId); 
        
        tblQLDTTXAHoSoXetTuyen.setKhoaId(tblQLDTTXADMKhoaService.gettblQLDTTXADMKhoa(new Long(khoaId))); 
        tblQLDTTXAHoSoXetTuyen.setNganhId(tblQLDTTXADMNganhService.gettblQLDTTXADMNganh(new Long(nganhId))); 
        preUpdate(msg,tblQLDTTXAHoSoXetTuyen); 
       if (msg.isPreMessage_b()) 
       { 
           tblQLDTTXAHoSoXetTuyenService.updatetblQLDTTXAHoSoXetTuyen(tblQLDTTXAHoSoXetTuyen); 
           postUpdate(msg, tblQLDTTXAHoSoXetTuyen); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_QLDTTXA_HoSoXetTuyen Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 }

public String getDiDong() {
	return diDong;
}

public void setDiDong(String diDong) {
	this.diDong = diDong;
} 
 } 
 
